package com.zfj.TreeSet;

import com.zfj.HashSet.Person;

import java.util.Iterator;
import java.util.TreeSet;

/**
 * @author zfj
 * @date 2022/3/7 -16:01
 * 元素必须实现Comparable接口，CompareTo()方法返回值为0，该重复
 */
public class Demo2 {
	public static void main(String[] args) {
		TreeSet<Person> people=new TreeSet<Person>();
		Person p1=new Person("张三",20);
		Person p2=new Person("李四",20);
		Person p3=new Person("王五",20);
		people.add(p1);
		people.add(p2);
		people.add(p3);
		System.out.println(people.toString());
		//删除
		people.remove(p1);
		System.out.println(people.size());
		//遍历
		//遍历
		for (Person person : people) {
			System.out.println(person);
		}
		System.out.println("=========迭代器=========");
		Iterator<Person> iterator = people.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		System.out.println(people.contains(new Person("李四", 20)));
		System.out.println(people.isEmpty());

	}
}
